/****************************************************************************/
/*
* indirect api for exteral module get/set/save xml.
*/
/****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cms_common.h"
#include "cms_msg.h"
#include "cms_log.h"
#include "libmdm.h"
#include "cms_mdm.h"
#include "cms_event.h"

int cmsXml_subcribeObject(
	uint32_t numOfEvent,
	const uint32_t *eventId, 
	uint32_t numOfObj, 
	const uint32_t *objArray,
	void* (*event_rtn)(void *), 
	void *arg)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int taskMsqId = -1;

	/*subcribe event*/
	if((numOfEvent != 0) && (eventId != NULL)){
		if(cms_subcribeEvent(numOfEvent, eventId, event_rtn, arg) == CMS_NOK){
			CMS_LOG(LL_ERROR, "subscribe dbus object notify event fail.\n");
			return -1;
		}
	}

	/*subcribe obj*/
	if((numOfObj != 0) &&(objArray != NULL)){
		if((pReqMsg = cms_createRequestMsg(0)) == NULL)
			return -1;
		
		/*fill object info to pReq msg*/
		cms_requestSubscribeEvent(pReqMsg, numOfObj, objArray);
		if((taskMsqId = msgget(CMSTASK_STATS_KEY, 0666)) == -1){
			CMS_LOG(LL_ERROR,"get dst module cms_task stats queue failed, key 0x%x.\n", CMSTASK_STATS_KEY);
			cms_msgAndShmFree(pReqMsg);
			return -1;
		}
		
		if(cms_sendMsg(pReqMsg, taskMsqId) == CMS_NOK){
			cms_msgAndShmFree(pReqMsg);
			CMS_LOG(LL_ERROR,"send msg to task fail.\n");
			return -1;
		}
		
		cms_msgFree(pReqMsg);
	}
	
	CMS_LOG(LL_DEBUG, "Exit\n");
	
	return 0;
}

int cmsXml_unSubcribeObject(
	uint32_t numOfEvent, 
	const uint32_t *eventId,
	uint32_t numOfObj, 
	const uint32_t *objArray)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int taskMsqId = -1;

	/*unsubcribe event*/
	if((numOfEvent != 0) && (eventId != NULL)){
		if(cms_unSubcribeEvent(numOfEvent, eventId) == CMS_NOK){
			CMS_LOG(LL_ERROR, "unsubscribe dbus object notify event fail.\n");
			return -1;
		}
	}

	/*unsubcribe obj*/
	if((numOfObj != 0) &&(objArray != NULL)){
		if((pReqMsg = cms_createRequestMsg(0)) == NULL)
			return -1;

		/*fill object info to pReq msg*/
		cms_requestUnsubscribeEvent(pReqMsg, numOfObj, objArray);
		if((taskMsqId = msgget(CMSTASK_STATS_KEY, 0666)) == -1){
			CMS_LOG(LL_ERROR,"get dst module cms_task stats queue failed, key 0x%x.\n", CMSTASK_STATS_KEY);
			cms_msgAndShmFree(pReqMsg);
			return -1;
		}
		
		if(cms_sendMsg(pReqMsg, taskMsqId) == CMS_NOK){
			cms_msgAndShmFree(pReqMsg);
			CMS_LOG(LL_ERROR,"send msg to task fail.\n");
			return -1;
		}
		
		cms_msgFree(pReqMsg);
	}
	
	CMS_LOG(LL_DEBUG, "Exit\n");
	
	return 0;
}

static int cms_sendMsgToDb(cmsMsgCb_t *pReqMsg, uint32_t timeOut){
	int dbMsqId = -1;
	int dbKey = -1;
	
	genKeyByName(CMS_DB, &dbKey, NULL);
	if((dbMsqId = msgget(dbKey, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module msqId failed, key 0x%x.\n", dbKey);
		return -1;
	}
	
	return cms_SendRecvMsgResult(pReqMsg, dbMsqId, timeOut);
}


static int cms_sendMsgToDb_noReply(cmsMsgCb_t *pReqMsg){
	int dbMsqId = -1;
	int dbKey = -1;
	
	genKeyByName(CMS_DB, &dbKey, NULL);
	if((dbMsqId = msgget(dbKey, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module msqId failed, key 0x%x.\n", dbKey);
		return -1;
	}
	
	if(cms_sendMsgNoReply(pReqMsg, dbMsqId) < 0){
		CMS_LOG(LL_ERROR, "send msg fail.\n");
		return -1;
	}
	
	return 0;
}

#if 0
static int cms_sendMsgToTask(cmsMsgCb_t *pReqMsg, uint32_t timeOut){
	int taskMsqId = -1;
	int taskKey = -1;
	
	genKeyByName(CMS_TASK, &taskKey, NULL);
	if((taskMsqId = msgget(taskKey, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module msqId failed, key 0x%x.\n", taskKey);
		return CMS_NOK;
	}
	
	return cms_SendRecvMsgResult(pReqMsg, taskMsqId, timeOut);
}
#endif

static int cms_sendMsgToStats(cmsMsgCb_t *pReqMsg, uint32_t timeOut){
	int taskMsqId = -1;
	
	if((taskMsqId = msgget(CMSTASK_STATS_KEY, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module stats queue failed, key 0x%x.\n", CMSTASK_STATS_KEY);
		return CMS_NOK;
	}
	
	return cms_SendRecvMsgResult(pReqMsg, taskMsqId, timeOut);
}


/*
	Description: 
		use to indirect get parameter
	Parameters:
		objOff: the object offset
		parameter:	pointer array of p1, p2, p3,....
		count: parameter number
	return:
		return pointer array of (name, type_size, value)
*/
parameterValue_t *cmsXml_getParameterIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL, *pRecvMsg = NULL;
	cmsMsg_action_t *pAction = NULL;
	parameterValue_t *value, *ptr;
	cmsoffset_t valueOffset = 0;
	void *valueOffAddr = NULL;
	uint32_t type= 0;
	int dbMsqId = -1;
	int dbKey = -1;
	int paraCount = 0;
	int i = 0, j = 0;
	
	if((xmlShmCb == NULL) || (parameter == NULL)){
		CMS_LOG(LL_ERROR, "func para is NULL.\n");
		return NULL;
	}

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return NULL;
	}

	cms_requestSelObjByOffset(pReqMsg,objOff);
	for(i = 0; i < count; i++){
		cms_requestGetPara(pReqMsg, *(parameter + i));
		CMS_LOG(LL_SPEW, "get parameter, actionNum is %d\n", pReqMsg->header.actionNum);
	}
	
	/*send request to DB.*/
	genKeyByName(CMS_DB, &dbKey, NULL);
	if((dbMsqId = msgget(dbKey, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module msqId failed, key 0x%x.\n", dbKey);
		cms_msgFree(pReqMsg);
		return NULL;
	}
	
	pRecvMsg = cms_SendRecvMsg(pReqMsg, dbMsqId, DEFAULT_TIMEOUT);
	if(pRecvMsg == NULL){
		CMS_LOG(LL_ERROR, "recv msg fail.\n");
		cms_msgFree(pReqMsg);
		return NULL;
	}else{
		if(IS_NACK(pRecvMsg->header.flag)){
			CMS_LOG(LL_ERROR, "recv msg header NACK!!!\n");
			cms_msgFree(pReqMsg);
			cms_msgFree(pRecvMsg);
			return NULL;
		}
	}

	/*parse*/
	paraCount = pRecvMsg->header.actionNum;
	if(paraCount-1 != count){
		CMS_LOG(LL_ERROR, "request num(%d) is diff with reponse num(%d).\n", count, paraCount);
		cms_msgFree(pReqMsg);
		cms_msgFree(pRecvMsg);
		return NULL;
	}else{
		ptr = (parameterValue_t *)calloc(count, sizeof(parameterValue_t));
		value = (parameterValue_t *)ptr;
	}
	
	/*set value/type/parametername to ptr*/
	for(i = 0, j = 0; i < paraCount; i++){
		pAction = cms_parseMsgAction(pRecvMsg);
		if(pAction == NULL){
			CMS_LOG(LL_ERROR, "msg action parse fail.\n");
			cms_msgFree(pReqMsg);
			cms_msgFree(pRecvMsg);
			safe_free(ptr);
			return NULL;
		}
		GET_TYPE(type, pAction->action->type);
		CMS_LOG(LL_SPEW,"the action type is 0x%x\n", type);
		if(type == CMS_MSG_ACT_GETPARA){
			valueOffAddr = pAction->paraValue->value;
			valueOffset = *(cmsoffset_t *)valueOffAddr;
			
			value->name = *(parameter + j);
			value->value = cmsXmlGetObjRealAddr(xmlShmCb, valueOffset);
			value->type_size = pAction->paraValue->typeSizeOfValue;
			CMS_LOG(LL_SPEW, "getpara, name %s, value %s, type 0x%x\n", value->name, (char *)value->value,value->type_size);
			value++;
			j++;
		}
	}

	/*free msg block*/
	cms_msgFree(pReqMsg);
	cms_msgFree(pRecvMsg);
	
	return ptr;
}

uint32_t cmsXml_getParameterAttrIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsg_action_t *pAction = NULL;
	cmsMsgCb_t *pReqMsg = NULL;
	cmsMsgCb_t  *pRecvMsg = NULL;
	int dbMsqId = -1;
	int dbKey = -1;
	uint32_t actionNum = 0;
	uint32_t attr = 0;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return 0;
	}
	cms_requestSelObjByOffset(pReqMsg, objOff);
	cms_requestGetAttr(pReqMsg, parameter);


	genKeyByName(CMS_DB, &dbKey, NULL);
	if((dbMsqId = msgget(dbKey, 0666)) == -1){
		CMS_LOG(LL_ERROR,"get dst module msqId failed, key 0x%x.\n", dbKey);
		cms_msgFree(pReqMsg);
		return 0;
	}
	
	pRecvMsg = cms_SendRecvMsg(pReqMsg, dbMsqId, DEFAULT_TIMEOUT);
	if(pRecvMsg == NULL){
		CMS_LOG(LL_ERROR, "recv msg fail.\n");
		cms_msgFree(pReqMsg);
		return 0;
	}else{
		if(IS_NACK(pRecvMsg->header.flag)){
			CMS_LOG(LL_ERROR, "recv msg header NACK!!!\n");
			cms_msgFree(pReqMsg);
			cms_msgFree(pRecvMsg);
			return 0;
		}
	}

	/*parse attr*/
	actionNum = pRecvMsg->header.actionNum;
	while(actionNum > 0){
			pAction = cms_parseMsgAction(pRecvMsg);
			if(pAction == NULL){
				CMS_LOG(LL_ERROR, "msg action parse fail.\n");
				cms_msgFree(pReqMsg);
				cms_msgFree(pRecvMsg);
				return 0;
			}

			switch(pAction->action->type){
				case CMS_MSG_ACT_GETATTR:
					attr = pAction->paraAttr->attr;
					break;
				default:
					break;
			}
			actionNum--;
	}
	
	/*free*/
	cms_msgFree(pReqMsg);
	cms_msgFree(pRecvMsg);
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return attr;
}

uint32_t cmsXml_getParameterExtAttrIndirct(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter)
{
	return 0;
}

int cmsXml_setIndexObjectIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, int active)
{
	return 0;
}

int cmsXml_setParameterNnotify(
	cmsXmlCb_t *xmlShmCb, 
	cmsoffset_t objOffset, 
	paraValueSettingList_t *parameterList,
	cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	pReqMsg->header.taskNotify = FALSE;
	cms_requestSelObjByOffset(pReqMsg, objOffset);
	
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		if(strlen(curPara->parameter) != 0){
			if(curPara->type == PARAMETER_TYPE_STRING)
				CMS_LOG(LL_SPEW, "para %s, value %s, type 0x%x\n", curPara->parameter, curPara->value, curPara->type);
			else
				CMS_LOG(LL_SPEW, "para %s, value %d , type 0x%x\n", curPara->parameter, *((uint8_t *)curPara->value), curPara->type);
			
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				if(replyFlag == TRUE)
					ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				else
					ret = cms_sendMsgToDb_noReply(pReqMsg);

				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						pReqMsg->header.taskNotify = FALSE;
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						CMS_LOG(LL_FATAL,"Set fail, has not register to cms_core or has deregister to cms_core");
						return -1;
					}
				}
			}
		}
		
		curPara = curPara->next;
		
	}
	
	/*get the dst module's msq id*/
	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);

	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	
	CMS_LOG(LL_SPEW, "Exit\n");
	/*CMS_OK:0, CMS_NOK: -1, CMS_POK: -2(send ok but recv timeout)*/
	return ret;
}

int cmsXml_cwmpSetParameterNnotify(
	cmsXmlCb_t *xmlShmCb, 
	cmsoffset_t objOffset, 
	paraValueSettingList_t *parameterList,
	cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	pReqMsg->header.cwmpNotify = FALSE;
	cms_requestSelObjByOffset(pReqMsg, objOffset);
	
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		if(strlen(curPara->parameter) != 0){
			if(curPara->type == PARAMETER_TYPE_STRING)
				CMS_LOG(LL_SPEW, "para %s, value %s, type 0x%x\n", curPara->parameter, curPara->value, curPara->type);
			else
				CMS_LOG(LL_SPEW, "para %s, value %d , type 0x%x\n", curPara->parameter, *((uint8_t *)curPara->value), curPara->type);

			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				if(replyFlag == TRUE)
					ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				else
					ret = cms_sendMsgToDb_noReply(pReqMsg);
				
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						pReqMsg->header.cwmpNotify = FALSE;
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						return -1;
					}
				}
			}
		}
		
		curPara = curPara->next;
	}
	
	/*get the dst module's msq id*/
	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	
	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_setParameterIndirectByParaList(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestSelObjByOffset(pReqMsg, objOffset);
	
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		
		if(strlen(curPara->parameter) != 0){
			if(curPara->type == PARAMETER_TYPE_STRING)
				CMS_LOG(LL_SPEW, "para %s, value %s, type 0x%x\n", curPara->parameter, curPara->value, curPara->type);
			else
				CMS_LOG(LL_SPEW, "para %s, value %d , type 0x%x\n", curPara->parameter, *((uint8_t *)curPara->value), curPara->type);
			
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK){
					cms_msgAndShmFree(pReqMsg);
				}else{
					cms_msgFree(pReqMsg);
				}

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						return -1;
					}
				}
			}
		}
		
		curPara = curPara->next;
	}
	
	/*get the dst module's msq id*/
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK){
		cms_msgAndShmFree(pReqMsg);
	}else{
		cms_msgFree(pReqMsg);
	}
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_setParameterIndirectByParaList_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestSelObjByOffset(pReqMsg, objOffset);
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK){
					cms_msgAndShmFree(pReqMsg);
				}else{
					cms_msgFree(pReqMsg);
				}

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						return -1;
					}
				}
			}
		}
		curPara = curPara->next;
	}
	
	/*get the dst module's msq id*/
	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK){
		cms_msgAndShmFree(pReqMsg);
	}else{
		cms_msgFree(pReqMsg);
	}
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}


int cmsXml_setParameterIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;
	int i = 0;
	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestSelObjByOffset(pReqMsg, objOffset);
	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i),*(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) ) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if((count-1) != 0){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						return -1;
					}
				}
			}
		}

		count--;
		i +=3;
	}

	/*get the dst module's msq id*/
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_setParameterIndirect_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;
	int i = 0;
	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestSelObjByOffset(pReqMsg, objOffset);
	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i),*(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) ) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if((count-1) != 0){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjByOffset(pReqMsg, objOffset);
					}else{
						return -1;
					}
				}
			}
		}
		count--;
		i +=3;
	}

	/*get the dst module's msq id*/
	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	
	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}

int cmsXml_setParameterByOID(
	cmsXmlCb_t *xmlShmCb, 
	uint32_t objID, 
	uint64_t objIA, 
	paraValueSettingList_t *parameterList,
	cmsBoolean replyFlag,
	uint32_t timtOut,
	cmsBoolean notifyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = CMS_NOK;
	
	/*create req msg*/
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return ret;
	}

	pReqMsg->header.taskNotify = notifyFlag;
	cms_requestSelObjById(pReqMsg, objID, objIA);
	
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		
		if(strlen(curPara->parameter) != 0){
			if(curPara->type == PARAMETER_TYPE_STRING)
				CMS_LOG(LL_SPEW, "para %s, value %s, type 0x%x\n", curPara->parameter, curPara->value, curPara->type);
			else
				CMS_LOG(LL_SPEW, "para %s, value %d , type 0x%x\n", curPara->parameter, *((uint8_t *)curPara->value), curPara->type);

			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				if(replyFlag == TRUE)
					ret = cms_sendMsgToDb(pReqMsg, timtOut);
				else
					ret = cms_sendMsgToDb_noReply(pReqMsg);
				
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						pReqMsg->header.taskNotify = notifyFlag;
						cms_requestSelObjById(pReqMsg, objID, objIA);
					}else{
						return -1;
					}
				}
			}
		}
		
		curPara = curPara->next;
	}

	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, timtOut);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_setOneParameterByOIDIndirect(cmsXmlCb_t *xmlShmCb,uint32_t OID, uint64_t IA, char *parameter, uint32_t type, void *value)
{
	void *object = NULL;
	uint32_t objOff = 0;
	setParaValue_t *setPtr, *tmpPtr;

	if((parameter == NULL) || (value == NULL))
		return -1;
	
	object = cmsXml_GetObjectByOID(xmlShmCb, OID, IA, 1);
	if(object){

		objOff = cmsXmlGetPtrOffset(xmlShmCb, object);

		tmpPtr = setPtr = malloc(sizeof(setParaValue_t)*1);

		setPtr->parameter = parameter;
		setPtr->value = value;
		setPtr->type = &type;

		cmsXml_setParameterIndirect(xmlShmCb, objOff, 1, (char **)tmpPtr);
		free(tmpPtr);
		
	}else{
		return -1;
	}
	
	return 0;
}

int cmsXml_setOneParameterByPathIndirect(cmsXmlCb_t *xmlShmCb,char *objPath, char *parameter, uint32_t type, void *value)
{
	void *object = NULL;
	uint32_t objOff = 0;
	setParaValue_t *setPtr, *tmpPtr;

	if((parameter == NULL) || (value == NULL))
		return -1;
	
	object = cmsXml_GetObjectByName(xmlShmCb, objPath, 1);
	if(object){

		objOff = cmsXmlGetPtrOffset(xmlShmCb, object);

		tmpPtr = setPtr = malloc(sizeof(setParaValue_t)*1);

		setPtr->parameter = parameter;
		setPtr->value = value;
		setPtr->type = &type;

		cmsXml_setParameterIndirect(xmlShmCb, objOff, 1, (char **)tmpPtr);
		free(tmpPtr);
		
	}else{
		return -1;
	}
	
	return 0;
}


int cmsXml_setParameterAttrIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t attr, int active)
{	
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	cms_requestSelObjByOffset(pReqMsg, objOff);
	cms_requestSetAttr(pReqMsg, parameter, attr, active);

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_setParameterAttrIndirect_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t attr, int active)
{	
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	cms_requestSelObjByOffset(pReqMsg, objOff);
	cms_requestSetAttr(pReqMsg, parameter, attr, active);

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);
	
	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}


int cmsXml_setParameterExtAttrIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t flags, int active)
{
	return 0;
}

int cmsXml_addObjectByOIDIWithParaListIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestAddObjectByOID(pReqMsg, OID, objIA);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjById(pReqMsg, OID, objIA);
					}else{
						return -1;
					}
				}
			}
		}
		curPara = curPara->next;
	}

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_addObjectByOIDNnotify(
	cmsXmlCb_t *xmlShmCb, 
	uint32_t OID, 
	uint64_t objIA, 
	paraValueSettingList_t *paraList, 
	cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	pReqMsg->header.taskNotify = FALSE;
	cms_requestAddObjectByOID(pReqMsg, OID, objIA);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				if(replyFlag == TRUE)
					ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				else
					ret = cms_sendMsgToDb_noReply(pReqMsg);
				
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						pReqMsg->header.taskNotify = FALSE;
						cms_requestSelObjById(pReqMsg, OID, objIA);
					}else{
						return -1;
					}
				}
			}
		}
		curPara = curPara->next;
	}

	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_addObjectByOIDIWithParaListIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestAddObjectByOID(pReqMsg, OID, objIA);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if(curPara->next != NULL){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjById(pReqMsg, OID, objIA);
					}else{
						return -1;
					}
				}
			}
		}
		curPara = curPara->next;
	}

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}


int cmsXml_addObjectByOIDIAIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int i = 0;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestAddObjectByOID(pReqMsg, OID, objIA);

	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i), *(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) )== -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if((count -1) != 0){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjById(pReqMsg, OID, objIA);
					}else{
						return -1;
					}
				}
			}
		}

		count--;
		i +=3;
	}

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_addObjectByOIDIAIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int i = 0;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestAddObjectByOID(pReqMsg, OID, objIA);

	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i), *(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) )== -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
				ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

				if((count -1) != 0){
					pReqMsg = cms_createRequestMsg(0);
					if(pReqMsg != NULL){
						cms_requestSelObjById(pReqMsg, OID, objIA);
					}else{
						return -1;
					}
				}
			}
		}

		count--;
		i +=3;
	}

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}

int cmsXml_delObjectByOIDIAIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestDelObjectByOID(pReqMsg, OID, objIA);

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_delObjectByOIDIANnotify(
	cmsXmlCb_t *xmlShmCb, 
	uint32_t OID, 
	uint64_t objIA, 
	cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	pReqMsg->header.taskNotify = FALSE;
	cms_requestDelObjectByOID(pReqMsg, OID, objIA);

	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_delObjectByOIDIAIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestDelObjectByOID(pReqMsg, OID, objIA);

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}

int cmsXml_addObjectByPathNameNnotify(
	cmsXmlCb_t *xmlShmCb, 
	char *objPathName, 
	paraValueSettingList_t *paraList,
	cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	paraValueSettingList_t *curPara = NULL;
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	pReqMsg->header.taskNotify = FALSE;
	cms_requestAddObjectByPath(pReqMsg, objPathName);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
			    if(replyFlag == TRUE)
					ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				else
					ret = cms_sendMsgToDb_noReply(pReqMsg);
				
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

			    if(curPara->next != NULL){
			        pReqMsg = cms_createRequestMsg(0);
			        if(pReqMsg != NULL){
						pReqMsg->header.taskNotify = FALSE;
			            cms_requestSelObjByName(pReqMsg, objPathName);
			        }else{
			            return -1;
			        }
			    }
			}
		}
		curPara = curPara->next;
	}

	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_addObjectByPathNameWithParaList(cmsXmlCb_t *xmlShmCb, char *objPathName, paraValueSettingList_t *paraList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	paraValueSettingList_t *curPara = NULL;
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	cms_requestAddObjectByPath(pReqMsg, objPathName);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
			    ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

			    if(curPara->next != NULL){
			        pReqMsg = cms_createRequestMsg(0);
			        if(pReqMsg != NULL){
			            cms_requestSelObjByName(pReqMsg, objPathName);
			        }else{
			            return -1;
			        }
			    }
			}
		}
		curPara = curPara->next;
	}

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_addObjectByPathNameWithParaList_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName, paraValueSettingList_t *paraList)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	paraValueSettingList_t *curPara = NULL;
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestAddObjectByPath(pReqMsg, objPathName);

	curPara = paraList;
	while(curPara){
		if(curPara->parameter != NULL){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
			    ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

			    if(curPara->next != NULL){
			        pReqMsg = cms_createRequestMsg(0);
			        if(pReqMsg != NULL){
			            cms_requestSelObjByName(pReqMsg, objPathName);
			        }else{
			            return -1;
			        }
			    }
			}
		}
		curPara = curPara->next;
	}

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}


int cmsXml_addObjectByPathNameIndirect(cmsXmlCb_t *xmlShmCb, char *objPathName, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int i = 0;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestAddObjectByPath(pReqMsg, objPathName);

	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i), *(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) ) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
			    ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

			    if((count -1) != 0){
			        pReqMsg = cms_createRequestMsg(0);
			        if(pReqMsg != NULL){
			            cms_requestSelObjByName(pReqMsg, objPathName);
			        }else{
			            return -1;
			        }
			    }
			}
		}

		count--;
		i +=3;
	}

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_addObjectByPathNameIndirect_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName, int count, char **parameter)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int i = 0;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestAddObjectByPath(pReqMsg, objPathName);

	/*set parameter in msg*/
	while(count){
		if(*(parameter + i) != NULL){
			if(cms_requestSetPara(pReqMsg, *(parameter + i), *(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) ) == -1)
				break;
			if(pReqMsg->shmCnt == DATA_SIZE){
			    ret = cms_sendMsgToDb_noReply(pReqMsg);
				if(ret == CMS_NOK)
					cms_msgAndShmFree(pReqMsg);
				else
					cms_msgFree(pReqMsg);

			    if((count -1) != 0){
			        pReqMsg = cms_createRequestMsg(0);
			        if(pReqMsg != NULL){
			            cms_requestSelObjByName(pReqMsg, objPathName);
			        }else{
			            return -1;
			        }
			    }
			}
		}

		count--;
		i +=3;
	}

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}


int cmsXml_delObjectByPathNameIndirect(cmsXmlCb_t *xmlShmCb, char *objPathName)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestDelObjectByPath(pReqMsg, objPathName);

	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_delObjectByPathNameNnotify(cmsXmlCb_t *xmlShmCb, char *objPathName, cmsBoolean replyFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	pReqMsg->header.taskNotify = FALSE;
	cms_requestDelObjectByPath(pReqMsg, objPathName);

	if(replyFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_delObjectByPathNameIndirect_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_requestDelObjectByPath(pReqMsg, objPathName);

	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}

int cmsXml_setMultiObj(
	cmsXmlCb_t *xmlShmCb, 
	cms_multiObjSettingList_t *pMultiObjList, 
	cmsBoolean notifyFlag, 
	cmsBoolean replayFlag)
{
	CMS_LOG(LL_SPEW, "Extrance\n");

	cmsMsgCb_t *pReqMsg = NULL;
	cms_multiObjSettingList_t *curObjList = NULL;
	paraValueSettingList_t *curPara = NULL;
	int ret = -1;

	if((xmlShmCb == NULL) || (pMultiObjList == NULL)){
		CMS_LOG(LL_ERROR, "NULL input param.\n");
		return -1;
	}

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}
	
	pReqMsg->header.isMutliObj = TRUE;
	pReqMsg->header.taskNotify = notifyFlag;

	curObjList = pMultiObjList;
	while(curObjList){
		if(curObjList->type == OBJ_ADD){
			if(curObjList->objectInfo.isPathName == TRUE){
				cms_requestAddObjectByPath(pReqMsg, curObjList->objectInfo.object.pathName);
			}else
				cms_requestAddObjectByOID(pReqMsg, curObjList->objectInfo.object.objOID.OID, curObjList->objectInfo.object.objOID.OIA);
			
			curPara = curObjList->paramList;
			while(curPara){
				if(curPara->parameter != NULL){
					if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
						break;
					if(pReqMsg->shmCnt == DATA_SIZE){
					    if(replayFlag == TRUE)
							ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
						else
							ret = cms_sendMsgToDb_noReply(pReqMsg);
						
						if(ret == CMS_NOK)
							cms_msgAndShmFree(pReqMsg);
						else
							cms_msgFree(pReqMsg);

					    if(curPara->next != NULL){
					        pReqMsg = cms_createRequestMsg(0);
					        if(pReqMsg != NULL){
								pReqMsg->header.isMutliObj = TRUE;
								pReqMsg->header.taskNotify = notifyFlag;
					            if(curObjList->objectInfo.isPathName == TRUE){
									cms_requestSelObjByName(pReqMsg, curObjList->objectInfo.object.pathName);
								}else
									cms_requestSelObjById(pReqMsg, curObjList->objectInfo.object.objOID.OID, curObjList->objectInfo.object.objOID.OIA);
					        }else{
					            return -1;
					        }
					    }
					}
				}
				curPara = curPara->next;
			}
		}else if(curObjList->type == OBJ_DEL){
			if(curObjList->objectInfo.isPathName == TRUE){
				cms_requestDelObjectByPath(pReqMsg, curObjList->objectInfo.object.pathName);
			}else
				cms_requestDelObjectByOID(pReqMsg, curObjList->objectInfo.object.objOID.OID, curObjList->objectInfo.object.objOID.OIA);
			
		}else if(curObjList->type == OBJ_SET){
			if(curObjList->objectInfo.isPathName == TRUE){
				cms_requestSelObjByName(pReqMsg, curObjList->objectInfo.object.pathName);
			}else
				cms_requestSelObjById(pReqMsg, curObjList->objectInfo.object.objOID.OID, curObjList->objectInfo.object.objOID.OIA);
			
			curPara = curObjList->paramList;
			while(curPara){
				if(curPara->parameter != NULL){
					if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1)
						break;
					if(pReqMsg->shmCnt == DATA_SIZE){
					    if(replayFlag == TRUE)
							ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
						else
							ret = cms_sendMsgToDb_noReply(pReqMsg);
						
						if(ret == CMS_NOK)
							cms_msgAndShmFree(pReqMsg);
						else
							cms_msgFree(pReqMsg);

					    if(curPara->next != NULL){
					        pReqMsg = cms_createRequestMsg(0);
					        if(pReqMsg != NULL){
								pReqMsg->header.isMutliObj = TRUE;
								pReqMsg->header.taskNotify = notifyFlag;
					            if(curObjList->objectInfo.isPathName == TRUE){
									cms_requestSelObjByName(pReqMsg, curObjList->objectInfo.object.pathName);
								}else
									cms_requestSelObjById(pReqMsg, curObjList->objectInfo.object.objOID.OID, curObjList->objectInfo.object.objOID.OIA);
					        }else{
					            return -1;
					        }
					    }
					}
				}
				curPara = curPara->next;
			}
		}
		
		curObjList = curObjList->next;
	}

	if(replayFlag == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


int cmsXml_SaveIndirect(cmsXmlCb_t *xmlShmCb)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	if(xmlShmCb == NULL){
		CMS_LOG(LL_ERROR, "xmlshmcb is NULL.\n");
		return ret;
	}
	
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_setSaveActionRequest(pReqMsg, xmlShmCb->shmId);
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_SaveNoReply(cmsXmlCb_t *xmlShmCb)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;

	if(xmlShmCb == NULL){
		CMS_LOG(LL_ERROR, "xmlshmcb is NULL.\n");
		return ret;
	}
	
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"save xml fail, create request msg fail.\n");
		return -1;
	}

	cms_setSaveActionRequest(pReqMsg, xmlShmCb->shmId);
	ret = cms_sendMsgToDb_noReply(pReqMsg);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return ret;
}



int cmsXml_restoreConfXml(char *fileName)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	char xmlUpgradePlace[64] = "/tmp/config.decrypt.xml";
	int ret = -1;

	if(fileName != NULL){
		memset(xmlUpgradePlace, 0, sizeof(xmlUpgradePlace));
		strcpy(xmlUpgradePlace, fileName);
	}

	if(access(xmlUpgradePlace, F_OK) == -1){
		CMS_LOG(LL_ERROR,"restore conf xml fail, file %s not exist.\n", xmlUpgradePlace);
		return -1;
	}
	
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"restore conf xml fail, create request msg fail.\n");
		return -1;
	}
	cms_requestRestoreConf(pReqMsg, xmlUpgradePlace);
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_savePreConf(char *fileName)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	char xmlUpgradePlace[64] = "/tmp/config.decrypt.xml";
	int ret = -1;

	if(fileName == NULL){
		CMS_LOG(LL_ERROR, "file is NULL\n");
		return CMS_NOK;
	}

	if(access(xmlUpgradePlace, F_OK) == -1){
		CMS_LOG(LL_ERROR,"restore pre conf xml fail, file %s not exist.\n", xmlUpgradePlace);
		return -1;
	}
	
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"restore conf xml fail, create request msg fail.\n");
		return -1;
	}
	cms_requestSavePreConf(pReqMsg, xmlUpgradePlace);
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmstask_notify_dosystem(char * cmd)
{
	int ret = 0;
	if ((cmd == NULL) || (*cmd == '\0'))
		return 1;

	ret = cms_eventNotify(CMS_EVENT_SYSTEM_CMD, PARAMETER_TYPE_STRING, cmd);
	return ret;
}

int cmsXml_restoreDefaultXml(uint32_t type)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = -1;
#ifdef GC_SUPPORT_PON_OR_ETHER_UPLINK	
	cmstask_notify_dosystem("gccli sys ethwan null");
#endif
	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"restore conf xml fail, create request msg fail.\n");
		return -1;
	}

#ifdef GC_APPS_AOS_NET
		cms_do_cmd("rm -rf /userconfig/config/ahsapd.conf");
		cms_do_cmd("rm -rf /tmp/tmpapp/*");
#endif

	cms_requestRestoreDefault(pReqMsg,type);
	ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}

int cmsXml_ObjectStats(uint32_t OID, uint64_t IA, uint32_t timeout)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t *pReqMsg = NULL;
	int ret = CMS_NOK;

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"object stats  fail(oid %u, %lx, timeout %u), create request msg fail.\n", OID, IA, timeout);
		return -1;
	}

	cms_requestUpdate(pReqMsg, OID, IA);
	ret = cms_sendMsgToStats(pReqMsg, timeout);
	if(ret == CMS_NOK){/*send msg fail*/
		cms_msgAndShmFree(pReqMsg);
	}else{
		if(ret != CMS_OK){
			char *fullPath;
			fullPath = cmsXml_GetFullpathByOIDIA(OID, IA);
			CMS_LOG(LL_ERROR, "cms stats OID=%d %s.\n", OID, fullPath?fullPath:"unknown");
			free(fullPath);
		}
		cms_msgFree(pReqMsg);
	}
	CMS_LOG(LL_SPEW, "Exit\n");

	return ret;
}

/*
	Description: 
		restore xml object param value in shm.
	Parameters:
		xmlShmCb 	-- share memory control block. 
		OID 	 	-- object id.
		objIA 	 	-- object instance array.
		restoreType	-- 1: retore to default xml vaule if exist,else restore to sysdef.xml default value;
					  	 2: restore to sysdef.xml default value;
		taskNotify	-- FALSE: only restore object param value but not notify task module;
					  	 TRUE: restore object param value and notify task module;
		msgReply	-- FALSE: no msg reply from cms_db, no block func;
					     TRUE: wait msg reply from cms_db ,block func;
	return:
		CMS_NOK -- fail 										
		CMS_OK	-- success	
*/
int cmsXml_objValueRestore(
	cmsXmlCb_t * xmlShmCb,
	uint32_t objId, 
	uint64_t objIA, 
	uint32_t restoreType,
	cmsBoolean taskNotify, 
	cmsBoolean msgReply)
{
	CMS_LOG(LL_SPEW, "Extrance\n");
	cmsMsgCb_t 	*pReqMsg = NULL;
	void		*object = NULL;
	int 		ret = CMS_NOK;
	cmsoffset_t	objOff = 0;

	if(xmlShmCb == NULL){
		CMS_LOG(LL_ERROR, "xmlShmCb is NULL\n");
		return ret;
	}

	object = cmsXmlGetObjectByOID(xmlShmCb, objId, objIA);
	if(object == NULL){
		CMS_LOG(LL_ERROR, "object is not exist, OID %u, OIA 0x%lx\n", objId, objIA);
		return ret;
	}
	objOff = cmsXmlGetPtrOffset(xmlShmCb, object);

	pReqMsg = cms_createRequestMsg(0);
	if(pReqMsg == NULL){
		CMS_LOG(LL_ERROR,"restore object fail, create request msg fail.\n");
		return ret;
	}
	pReqMsg->header.taskNotify = taskNotify;

	if(cms_requestObjRestore(pReqMsg, objOff, restoreType) == CMS_NOK){
		CMS_LOG(LL_ERROR,"restore object fail, set request msg fail.\n");
		cms_msgAndShmFree(pReqMsg);
		return ret;
	}
	
	if(msgReply == TRUE)
		ret = cms_sendMsgToDb(pReqMsg, DEFAULT_TIMEOUT);
	else
		ret = cms_sendMsgToDb_noReply(pReqMsg);
	
	if(ret == CMS_NOK)
		cms_msgAndShmFree(pReqMsg);
	else
		cms_msgFree(pReqMsg);

	CMS_LOG(LL_SPEW, "Exit\n");
	return (ret == CMS_NOK) ? CMS_NOK : CMS_OK;
}


#if 1/*api for dbus set*/
int cmsXml_setParameterIndirectByParaListWithCmsMsg(cmsXmlCb_t *xmlShmCb, cmsMsgCb_t *pReqMsg, cmsoffset_t objOffset, paraValueSettingList_t *parameterList)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");
	paraValueSettingList_t *curPara = NULL;
	int ret = CMS_OK;

	cms_requestSelObjByOffset(pReqMsg, objOffset);
	/*set parameter in msg*/
	curPara = parameterList;
	while(curPara){
		if(strlen(curPara->parameter) != 0){
			if(curPara->type == PARAMETER_TYPE_STRING)
				CMS_LOG(LL_DEBUG, "para %s, value %s, type 0x%x\n", curPara->parameter, curPara->value, curPara->type);
			else
				CMS_LOG(LL_DEBUG, "para %s, value %d , type 0x%x\n", curPara->parameter, *((uint8_t *)curPara->value), curPara->type);
			if(curPara->parameter != NULL)
				cms_requestSetPara(pReqMsg,  curPara->parameter, curPara->type, curPara->value);
		}
		curPara = curPara->next;
	}

	CMS_LOG(LL_DEBUG, "Exit\n");
	return ret;
}

int cmsXml_addObjectByOIDIAIndirectWithCmsMsg(cmsXmlCb_t *xmlShmCb, cmsMsgCb_t *pReqMsg, uint32_t OID, uint64_t objIA, int count, char **parameter)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");
	int i = 0;
	int ret = CMS_OK;

	cms_requestAddObjectByOID(pReqMsg,  OID,  objIA);

	/*set parameter in msg*/
	for(i = 0; i < count*3; i +=3){
		if(*(parameter + i)  != NULL){
			cms_requestSetPara(pReqMsg,  *(parameter + i), *(uint32_t *)(*(parameter + i + 2)), *(parameter + i + 1) );
		}
	}

	CMS_LOG(LL_DEBUG, "Exit\n");
	return ret;
}


int cmsXml_delObjectByOIDIAIndirectWithCmsMsg(cmsXmlCb_t *xmlShmCb, cmsMsgCb_t *pReqMsg, uint32_t OID, uint64_t objIA)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");
	int ret = CMS_OK;

	cms_requestDelObjectByOID(pReqMsg, OID, objIA);
	
	CMS_LOG(LL_DEBUG, "Exit\n");
	return ret;
}

int cmsXml_addObjectByOIDIWithParaListtWithCmsMsg(cmsXmlCb_t *xmlShmCb, cmsMsgCb_t *pReqMsg, uint32_t OID, uint64_t objIA, paraValueSettingList_t *parameterList)
{
	CMS_LOG(LL_DEBUG, "Extrance\n");

	paraValueSettingList_t *curPara = NULL;
	int ret = CMS_OK;
	cms_requestAddObjectByOID(pReqMsg,  OID,  objIA);

	/*set parameterList in msg*/
	curPara = parameterList;
	while(curPara){
		if((curPara->parameter != NULL) && (strlen(curPara->parameter) != 0)){
			if(cms_requestSetPara(pReqMsg, curPara->parameter, curPara->type, curPara->value) == -1){
				break;
			}
		}
		curPara = curPara->next;
	}
	CMS_LOG(LL_DEBUG, "Exit\n");
	return ret;
}

#endif

